package cn.phantom.interrrupt;

import java.util.concurrent.TimeUnit;

public class InterruptTest03 {

    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            while (true) {
                if (Thread.currentThread().isInterrupted()) {
                    System.out.println("-----Thread.currentThread().isInterrupted() = true, 程序结束");
                    break;
                }
                System.out.println("------hello interrupted");
            }
        }, "t1");

        t1.start();

        try {
            TimeUnit.MILLISECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            t1.interrupt();
        }, "t2").start();

    }
}
